<template>
  <div class="favorites-container">
    <div class="favorites-header">
      <h2>我的收藏</h2>
      <el-button type="text" @click="clearFavorites">清空收藏</el-button>
    </div>

    <div class="favorites-grid">
      <VideoCard
        v-for="video in favoritesList"
        :key="video.id"
        :video="video"
        @play="playVideo"
      />
    </div>

    <div v-if="favoritesList.length === 0" class="empty-state">
      <el-icon size="64"><Star /></el-icon>
      <p>暂无收藏视频</p>
      <el-button type="primary" @click="$router.push('/')">去发现好视频</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { Star } from '@element-plus/icons-vue'
import VideoCard from '@/components/common/VideoCard.vue'

const router = useRouter()

const favoritesList = ref([
  { id: 1, title: '庆余年 第二季', cover: '/covers/fav1.jpg', duration: '45:30', views: '1.2万' },
  { id: 2, title: '繁花', cover: '/covers/fav2.jpg', duration: '52:15', views: '8.5千' },
  { id: 3, title: '三体', cover: '/covers/fav3.jpg', duration: '48:45', views: '5.3千' },
  { id: 4, title: '狂飙', cover: '/covers/fav4.jpg', duration: '42:10', views: '2.1万' }
])

const playVideo = (video: any) => {
  router.push({
    path: '/player',
    query: { url: video.id }
  })
}

const clearFavorites = () => {
  favoritesList.value = []
}
</script>

<style lang="scss" scoped>
.favorites-container {
  padding: 20px;
  height: 100%;
  overflow-y: auto;
}

.favorites-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;

  h2 {
    font-size: 24px;
  }
}

.favorites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 400px;
  color: #b3b3b3;

  p {
    margin: 16px 0;
    font-size: 16px;
  }
}
</style>
